#define _CRT_SECURE_NO_WARNINGS 1
#include "string.h"

namespace wusaqi
{
	string::string(const char* str)
		:_size(strlen(str))
	{
		_str = new char[_size + 1];
		_capacity = _size;
		memcpy(_str, str, _size + 1);
	}

	string::~string()
	{
		delete[] _str;
		_str = nullptr;
		_capacity = _size = 0;
	}

	size_t string::size() const
	{
		return _size;
	}

	char& string::operator[](size_t i)
	{
		assert(i < _size);

		return _str[i];
	}

	const char& string::operator[](size_t i) const
	{
		assert(i < _size);

		return _str[i];
	}

	const char* string::c_str() const
	{
		return _str;
	}

	string::iterator string::begin()
	{
		return _str;
	}
	string::iterator string::end()
	{
		return _str + _size;
	}
}
